const state = {
  agentStore: {
    isShow: false,
    noFromHome: false,
    catgories: [],
    active: 'All',
    list: [],
    searchKeyword: ''
  }
}

const mutations = {
  SET_SHOW (state, val) {
    state.agentStore.isShow = val
  },
  SET_FROMHOME (state, val) {
    state.agentStore.noFromHome = val
  },
  SET_CATGORIES (state, list) {
    state.agentStore.catgories = [...list]
  },
  SET_ACTIVE (state, val) {
    state.agentStore.active = val
  },
  SET_LIST (state, list) {
    state.agentStore.list = [...list]
  },
  SET_SEARCH_KEYWORD (state, val) {
    state.agentStore.searchKeyword = val
  }
}

const actions = {
  setAgentShow ({ commit }, val) {
    commit('SET_SHOW', val)
  },
  setNoFromHome ({ commit }, val) {
    commit('SET_FROMHOME', val)
  },

  updateCatgoeries ({ commit, state }, { list, reset }) {
    if (reset) {
      commit('SET_CATGORIES', list)
    } else {
      commit('SET_CATGORIES', [...state.agentStore.catgories, ...list])
    }
  },

  setActiveTab ({ commit }, id) {
    commit('SET_ACTIVE', id)
  },

  updateList ({ commit, state }, { list, force }) {
    if (force) {
      commit('SET_LIST', list)
    } else {
      commit('SET_LIST', [...state.agentStore.list, ...list])
    }
  },

  updateSearchKeyword ({ commit }, keyword) {
    commit('SET_SEARCH_KEYWORD', keyword)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
